package com.doit.day01


import scala.util.control.Breaks._

object _07_循环的中断 {
  def main(args: Array[String]): Unit = {
    //打印的时候，打到5就不打了
    for(elem <- 1 to 10){

    }

    //类似于循环的守卫
    for(elem <- 1 to 10 if elem <= 5){
//      println(elem)
    }


    //抛一个异常
    try {
      for (elem <- 1 to 10) {
        if (elem == 6) {
          throw new Exception
        }
        println(elem)
      }
    } catch {
      case e:Exception =>
    }


    println("hehe")


    //break

/*    val breaks: Breaks = new Breaks()
    //调用的这个breakable这个方法里面，写的代码就代表是可以被中断的
    breaks.breakable(
      for (elem <- 1 to 10) {
        if (elem == 6) {
          breaks.break()
        }
        println(elem)
      }
    )*/


//    Breaks.breakable(
//      for (elem <- 1 to 10) {
//        if (elem == 6) {
//          Breaks.break()
//        }
//        println(elem)
//      }
//    )


    breakable(
      for (elem <- 1 to 10) {
        if (elem == 6) {
          break()
        }
        println(elem)
      }
    )






  }

}
